﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace Test
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {
        public MyHeader myHeaderMemberVariable = new MyHeader();


        [WebMethod]
        [SoapHeader("myHeaderMemberVariable")]
        public string HelloWorld()
        {
            if (myHeaderMemberVariable.Username != "liujie" && myHeaderMemberVariable.Password != "liujie")
                return "";

            return "Hello World";
        }

        [WebMethod]
        [SoapHeader("myHeaderMemberVariable")]
        public string Inset(int a, int b)
        {
            if (myHeaderMemberVariable.Username != "liujie" && myHeaderMemberVariable.Password != "liujie")
                return "用户名密码出错，不允许访问";

            // 访问数据库，插入到数据库中

            return "数据插入成功";
        }
    }

    /// <summary>
    /// SoapHeader 用于验证用户名密码
    /// </summary>
    public class MyHeader : SoapHeader
    {
        public string Username;
        public string Password;
    }

}
